import { VuexModule, Module, Action, Mutation, getModule } from 'vuex-module-decorators'
import store from '@/store'
import { getAction } from '@/api/common'

export interface IOemState {
  title: string
  logo: string
}

@Module({ dynamic: true, store, name: 'oem' })
class Oem extends VuexModule implements IOemState {
  public name = ''
  public title = ''
  public logo = ''
  public indexContent = ''
  public showLoginLogo = true
  public showIndexLogo = true
  public showIndexContent = true

  @Mutation
  private SET_TITLE(title: string) {
    this.title = title
  }

  @Mutation
  private SET_OEM_NAME(name: string) {
    this.name = name
  }

  @Mutation
  public SET_LOGO(logo: string) {
    this.logo = logo
  }

  @Mutation
  public SET_INDEX_CONTENT(indexContent: string) {
    this.indexContent = indexContent
  }

  @Mutation
  public SET_OEM(oem: any) {
    this.showLoginLogo = oem.showLoginLogo
    this.showIndexLogo = oem.showIndexLogo
    this.showIndexContent = oem.showIndexContent
  }

  @Action
  public async Init() {
    const { data } = await getAction(null, 'oem')
    this.SET_TITLE(data.title)
    this.SET_OEM_NAME(data.name)
    this.SET_INDEX_CONTENT(data.indexContent)
    this.SET_OEM(data)
  }
}

export const OemModule = getModule(Oem)
